//go:build wireinject
// +build wireinject

package wire

import (
	"ehsm_kms/internal/handler"
	"ehsm_kms/internal/repository"
	"ehsm_kms/internal/server"
	"ehsm_kms/pkg/app"
	"ehsm_kms/pkg/couchdb"
	"ehsm_kms/pkg/server/http"
	"github.com/google/wire"
	"go.uber.org/zap"
)

var repositorySet = wire.NewSet(
	couchdb.NewDB,
	repository.NewRepository,
	repository.NewUserInfoRepository,
	repository.NewCmkRepository,
	repository.NewQuotePolicyRepository,
)

var handlerSet = wire.NewSet(
	handler.NewHandler,
)

var serverSet = wire.NewSet(
	server.NewHTTPServer,
)

// build App
func newApp(httpServer *http.Server) *app.App {
	return app.NewApp(
		app.WithServer(httpServer),
		app.WithName("kms-api"),
	)
}

func NewWire(*zap.Logger, *http.Config, *couchdb.Config) (*app.App, func(), error) {
	panic(wire.Build(
		repositorySet,
		handlerSet,
		serverSet,
		newApp,
	))
}
